import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        list: JSON.parse(localStorage.getItem("list")) || [],

    },
    getters: {
    },
    mutations: {
        adds(state, v) {
            state.list.push(v);
            this.commit("location")
        },
        del(state, v) {
            state.list.splice(v, 1);
            this.commit("location")
        },
        del1(state) {
            state.list = state.list.filter(item => {
                return item.checked === false
            })
            this.commit("location")
        },
        check(state, v) {
            v.checked == true;
            console.log(v);
            this.commit("location")
        },
        ischecked(state, v) {
            state.list.forEach(item => {
                item.checked = v
            })
        },
        location(state) {
            localStorage.setItem("list", JSON.stringify(state.list));
        },
    },
    actions: {
    },
    modules: {
    },
    getters: {
        tjnum(state) {
            var num = 0
            state.list.forEach(item => {
                if (item.checked) {
                    num++
                }
            })
            return num
        }
    }
})
